package com.situ.mall.common.resolver;

import com.situ.mall.common.exception.BusinessException;
import com.situ.mall.common.exception.NoLoginException;
import com.situ.mall.common.vo.ResultVO;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionResolver {

    @ExceptionHandler(NoLoginException.class)
    public ResponseEntity<ResultVO> handler3() {
        return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(null);
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseEntity<ResultVO> handler1(BusinessException e) {
        ResultVO vo = new ResultVO();
        vo.setMsg(e.getMsg());
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(vo);
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity<ResultVO> handler2(Exception e) {
        e.printStackTrace();
        ResultVO vo = new ResultVO();
        vo.setMsg("内部服务处理错误");
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(vo);
    }
}
